import { myRequest } from '@/util/api.js'

//获取默认 信息
export function defaultInfo() {
	return myRequest('common/getConfig')
}


//微信登陆
export function login(data){
	return myRequest('staff/wxLogin',data)
}
//钉钉登陆
export function login2(data){
	return myRequest('staff/dingLogin?code=' + data, null, 'get')
}

export function islog() {
	return myRequest('staff/isLogin')
}

// https://crm.qdsd.vip/addons/qingdong/staff/dingLogin
export function dingLogin() {
	return myRequest('staff/dingLogin')
}
//测试
export function islogin() {
	return myRequest('staff/test')
}

//新版 登录
export function netNewLogin(data) {
	return myRequest('staff/login',data)
}


//退出登录
export function netOutLogin() {
	return myRequest('staff/logout')
}

//获取地图 key
export function netMapKey() {
	return myRequest('common/getConfig')
}

//发送code  给后台  获取用户信息
export function netSendCode(data) {
	return myRequest('staff/wechatBind',data)
}

//判断是否绑定微信
export function nerIsbindWechat(param){
	return myRequest('staff/staffBind', param, 'GET')
}

//发送code  小程序静默登录
export function netProgramLogin(code, data) {
	return myRequest('staff/programLogin?code=' + code,data)
}
//发送code  公众号静默登录
export function netWechatLogin(code, data) {
	return myRequest('staff/netWechatLogin?code=' + code,data)
}


export function netGetChainStoreList(data) {
	return myRequest('store/getChainStoreList',data, 'GET')
}

//发送code  公众号静默登录
export function setAppCtx(data) {
	let userinfo = data.userinfo;
	let storeinfo = data.storeinfo;
	uni.setStorageSync('userinfo',userinfo) 
	uni.setStorageSync('rules',userinfo.rules) 
	uni.setStorageSync('token',data.token)
	uni.setStorageSync('sid', storeinfo.id);
	uni.setStorageSync('storeinfo', storeinfo);
	
	uni.setStorageSync('staff_id', userinfo.id);
	uni.setStorageSync('storeinfo', storeinfo);
}


export function getAppCtx(data) {
	let ctx = {
		storeParameter: {}
	}
	let storeinfo = uni.getStorageSync('storeinfo')
	if(storeinfo && storeinfo.store_parameter) {
		ctx.loginedStore = storeinfo
		ctx.storeParameter = storeinfo.store_parameter//.is_cashier_sendsms
	}
	let userinfo = uni.getStorageSync('userinfo')
	if(userinfo) {
		ctx.loginedUser = userinfo
	}
	return ctx
}



